﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 结构体02
{
    struct Vector3
    {
        public float x, y, z;

        /// <summary>
        /// 构造器/构造方法，构造器的名称跟结构体的名称是一样，要是使用构造器，必须把所有的字段都赋值
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="c"></param>
        public Vector3(float a, float b, float c)
        {
            x = a;
            y = b;
            z = c;
        }

        /// <summary>
        /// 求模的方法
        /// </summary>
        /// <returns>模</returns>
        public float Maute()
        {
            return (float)Math.Sqrt(x * x + y * y + z * z);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // 结构体中有构造器和方法，还有字段

            Vector3 vec = new Vector3(1, 2, 3);
            Console.WriteLine(vec.z);
            Console.WriteLine(vec.Maute());
            Vector3 v = new Vector3();
            v.x = 10;
            Console.WriteLine(v.y);
        }
    }
}
